package com.tjmc.company.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tjmc.company.api.entity.CompanyCollectRecordsEntity;
import com.tjmc.company.service.CompanyCollectRecordsService;
import com.tjmc.recruit.common.core.util.R;
import com.tjmc.recruit.common.log.annotation.SysLog;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;

import com.tjmc.recruit.common.security.annotation.Inner;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import com.tjmc.recruit.common.security.annotation.HasPermission;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 企业收藏表
 *
 * @author recruit
 * @date 2024-12-12 14:23:13
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/companyCollectRecords" )
@Tag(description = "companyCollectRecords" , name = "企业收藏表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class CompanyCollectRecordsController {

    private final CompanyCollectRecordsService companyCollectRecordsService;

    /**
     * 分页查询
     * @param page 分页对象
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    public R getCompanyCollectRecordsPage(@ParameterObject Page page) {
        return R.ok(companyCollectRecordsService.selectCollectPage(page));
    }

    /**
     * 新增企业收藏表
     * @param companyCollectRecords 企业收藏表
     * @return R
     */
    @Operation(summary = "新增企业收藏表" , description = "新增企业收藏表" )
    @SysLog("新增企业收藏表" )
    @PostMapping
    public R save(@RequestBody CompanyCollectRecordsEntity companyCollectRecords) {
        LambdaQueryWrapper<CompanyCollectRecordsEntity> wrapper = new LambdaQueryWrapper<CompanyCollectRecordsEntity>()
                .eq(CompanyCollectRecordsEntity::getCollectAccountId, companyCollectRecords.getCollectAccountId());
        CompanyCollectRecordsEntity one = companyCollectRecordsService.getOne(wrapper);
        if (one != null) {
            return R.failed("用户简历已收藏");
        }
        return R.ok(companyCollectRecordsService.save(companyCollectRecords));
    }

    /**
     * 修改企业收藏表
     * @param companyCollectRecords 企业收藏表
     * @return R
     */
    @Operation(summary = "修改企业收藏表" , description = "修改企业收藏表" )
    @SysLog("修改企业收藏表" )
    @PutMapping
    public R updateById(@RequestBody CompanyCollectRecordsEntity companyCollectRecords) {
        return R.ok(companyCollectRecordsService.updateById(companyCollectRecords));
    }

    /**
     * 通过id删除企业收藏表
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除企业收藏表" , description = "通过id删除企业收藏表" )
    @SysLog("通过id删除企业收藏表" )
    @DeleteMapping
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(companyCollectRecordsService.removeBatchByIds(CollUtil.toList(ids)));
    }

    @Inner
    @GetMapping("/collectResume/{companyId}")
    public R collectResume(@PathVariable("companyId") Long companyId, @RequestParam Long userId) {
        return R.ok(companyCollectRecordsService.getCollectResume(companyId, userId));
    }
}
